import React from 'react';
import {connect} from 'dva';
import Chart from '../components/Chart';
import styles from '../styles/styles.less';
import {Link,routerRedux} from 'dva/router';
import BillTable from '../components/BillTable';
import Menu from '../components/Menu';
import Layout from '../components/Layout';
import Header from '../components/Header';
import {getCurrentMonth} from '../utils/tools';

//借收入  贷支出

function mapState(states)
{
  return {states};
}
export default connect(mapState)(function BankPage({states,dispatch,location})
{
  const model = 'cash';
  const state = states[model];
  let month = getCurrentMonth();
  let data = {
    month,
    items:[]
  };
  data.year = new Date().getFullYear();
  if(state.data.detail)
  {
    for(let i in state.data.detail)
    {
      if(parseInt(i) > 3)
      {
        let item = state.data.detail[i];
        let amount = item[3];
        if(item[2] == '贷')
        {
          amount = '-' + amount;
        }
        let day = new Date(item[0]);
        day = (day.getMonth() + 1) + '月' + day.getDate() + '日';
        data.items.push({
          day,
          desc:item[1],
          amount,
          over:item[5]
        });
      }
    }
  }
  data.items.reverse();
  function onSelect(month)
  {
    dispatch(routerRedux.push({
      pathname:'/'+model,
    }));
  }
  let title = state.loading?'加载中...':'现金详情';
  return (
    <Layout>
      <Header title={title} onSelect={onSelect} month={month} />
      <BillTable data={data} title="现金(元)" />
    </Layout>
  );
});